<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商品类型')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goodsclass-edit" th:object="${goodsClass}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">分类名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('goos_class_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group"   th:style="'display:'+ @{(*{parentId}!=null? 'none':'block')}">
                <label class="col-sm-3 control-label">是否首页展示：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('goods_class_home')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="isHome" th:value="${dict.dictValue}" th:field="*{isHome}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">图标：</label>
                <div class="col-sm-8">
                    <button type="button" class="layui-btn" id="upload_icon">上传图片</button>
                    <div class="layui-upload-list">
                        <div id="img_icon" style="padding: 5px;"><img th:src="*{icon}" style='height: 60px;width: 60px'></div>
                        <input type="hidden" id="icon" name="icon" th:field="*{icon}">
                        <input type="hidden" id="iconRealPath" name="iconRealPath" th:field="*{iconRealPath}">
                        <p id="icon_retry"></p>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">logo：</label>
                <div class="col-sm-8">
                    <button type="button" class="layui-btn" id="upload_logo">上传图片</button>
                    <div class="layui-upload-list">
                        <div id="img_logo" style="padding: 5px;"><img th:src="*{logo}" style='height: 60px;width: 60px'></div>
                        <input type="hidden" id="logo" name="logo" th:field="*{logo}">
                        <input type="hidden" id="logoRealPath" name="logoRealPath" th:field="*{logoRealPath}">
                        <p id="logo_retry"></p>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">分类头部图片：</label>
                <div class="col-sm-8">
                    <button type="button" class="layui-btn" id="upload_header">上传图片</button>
                    <div class="layui-upload-list">
                        <div id="img_header" style="padding: 5px;"><img th:src="*{header}" style='height: 60px;width: 60px'></div>
                        <input type="hidden" id="header" name="header" th:field="*{header}">
                        <input type="hidden" id="headerRealPath" name="headerRealPath" th:field="*{headerRealPath}">
                        <p id="header_retry"></p>
                    </div>
                </div>
            </div>
            <input id="treeId" name="parentId" type="hidden" th:field="${goodsClass.parentId}" />
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">上级分类：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeName" class="form-control" type="text" onclick="selectGoodsClassTree()" readonly="true" th:value="${goodsClass.parentName == null ? '主目录' : goodsClass.parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/goodsclass";
        $("#form-goodsclass-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-goodsclass-edit').serialize());
            }
        }



        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#upload_icon'
                , url: '/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#img_icon").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#icon").val(res.url);
                    $("#iconRealPath").val(res.realPath);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#icon_retry');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        })


        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#upload_header'
                , url: '/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#img_header").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#header").val(res.url);
                    $("#headerRealPath").val(res.realPath);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#header_retry');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        })



        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#upload_logo'
                , url: '/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#img_logo").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#logo").val(res.url);
                    $("#logoRealPath").val(res.realPath);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#logo_retry');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        })

        /*菜单管理-新增-选择菜单树*/
        function selectGoodsClassTree() {
            var treeId = $("#treeId").val();
            var menuId = treeId != 1 ? treeId : 1;
            var url = prefix + "/selectGoodsClassTree/system-goodsclass/" + menuId+"/b";
            var options = {
                title: '菜单选择',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

    </script>
</body>
</html>